{% extends "base.html" %}

{% block title %}Create Post - Flask Database Demo{% endblock %}

{% block content %}
<h2>Create New Post</h2>

<div class="row">
    <div class="col-md-6">
        <form method="POST">
            <div class="mb-3">
                <label for="author_id" class="form-label">Author</label>
                <select class="form-select" id="author_id" name="author_id" required>
                    <option value="">Select an author</option>
                    {% for user in users %}
                        <option value="{{ user.id }}" {% if request.form.get('author_id') == user.id|string %}selected{% endif %}>
                            {{ user.username }}
                        </option>
                    {% endfor %}
                </select>
                {% if errors and errors.author_id %}
                    <div class="text-danger">{{ errors.author_id }}</div>
                {% endif %}
            </div>
            
            <div class="mb-3">
                <label for="title" class="form-label">Title</label>
                <input type="text" class="form-control" id="title" name="title" 
                       value="{{ request.form.get('title', '') }}" required>
                {% if errors and errors.title %}
                    <div class="text-danger">{{ errors.title }}</div>
                {% endif %}
            </div>
            
            <div class="mb-3">
                <label for="body" class="form-label">Content</label>
                <textarea class="form-control" id="body" name="body" rows="5" required>{{ request.form.get('body', '') }}</textarea>
                {% if errors and errors.body %}
                    <div class="text-danger">{{ errors.body }}</div>
                {% endif %}
            </div>
            
            <button type="submit" class="btn btn-primary">Create Post</button>
            <a href="{{ url_for('posts') }}" class="btn btn-secondary">Cancel</a>
        </form>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5>Post Creation Guidelines</h5>
            </div>
            <div class="card-body">
                <p>When creating a new post, ensure:</p>
                <ul>
                    <li>An author is selected from existing users</li>
                    <li>Title is between 1-100 characters</li>
                    <li>Content is between 1-1000 characters</li>
                </ul>
                <p>This form demonstrates:</p>
                <ul>
                    <li>Foreign key relationships</li>
                    <li>Form validation with database constraints</li>
                    <li>Creating related records</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}